#!/bin/bash
#
# Copyright (C) 2011-2020 Aratelia Limited - Juan A. Rubio and contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#
# Bintray does not support xz compression currently. This script repackages
# control.tar and data.tar inside .deb packages of the various Python
# packages. To be used during Ubuntu Bionic and Debian Buster releases.
#

readonly DEBIAN_DIR=/root/work/debian

readonly TIZ_PYTHON_PROJECTS=( \
    tizgmusicproxy \
    tizsoundcloudproxy \
    tiztuneinproxy \
    tizyoutubeproxy \
    tizchromecastproxy \
    tizplexproxy \
    tizspotifyproxy \
    tiziheartproxy \
)

for proj in "${TIZ_PYTHON_PROJECTS[@]}"; do
    proj_dir="$DEBIAN_DIR/$proj"
    cd $proj_dir
    mkdir tmp && mv *.deb tmp && cd tmp && ar -x *.deb && mkdir data && mv data.tar.xz data && mkdir control && mv control.tar.xz control \
        && cd data && tar xf data.tar.xz && rm data.tar.xz && tar zcvf data.tar.gz * && mv data.tar.gz ../ && cd ../ \
        && cd control && tar xf control.tar.xz && rm control.tar.xz && tar zcvf control.tar.gz * && mv control.tar.gz ../ && cd ../ \
        && rm *.xz
    ar r python-"$proj"_"$TIZONIA_RELEASE_VERSION"-1_all.deb debian-binary data.tar.gz control.tar.gz && mv *.deb ../ && cd ../ && rm -rf tmp
done
